
// 全局配置

import variables from '@/assets/styles/element-variables.scss'  //全局主题
import defaultSettings from '@/settings'  //全局设置

const { showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings

const state = {
  theme: variables.theme,
  showSettings: showSettings,
  tagsView: tagsView,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    /**
     * hasOwnProperty() 方法是 Object 的原型方法    作用：检查对象中自有属性,不检查对象原形上的属性
     * 判斷state中是否有key属性  返回值：true/false
      */
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

